<template>
  <!-- 快速构建项目 -->
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <!-- table表格 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="序号" width="50"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"></el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column prop="level" label="等级">
          <!-- 用插槽来获取数据 -->
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level==='0'">一级</el-tag>
            <el-tag type="success" v-if="scope.row.level==='1'">二级</el-tag>
            <el-tag type="warning" v-if="scope.row.level==='2'">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  // 初始化的时候,就应该拿到数据
  created () {
    this.getRightList();
  },
  data () {
    return {
      tableData: []
    }
  },
  methods: {
    // 获取权限列表
    async getRightList () {
      const { data: { data, meta } } = await this.$axios.get(`rights/list`);
      // 返回的值是正确的,才需要展示页面的数据
      if (meta.status !== 200) {
        return this.$message.error('获取权限信息失败')
      }
      this.tableData = data
    }
  }
}
</script>

<style lang="css" scoped>
</style>
